home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 October / enter-2005-10.iso / files / jedit42install.exe / {app} / macros / Java / Preview_JavaDoc_Of_Current_Buffer.bsh < prev   
Encoding:
Text File  |  2004-08-29  |  30.2 KB  |  798 lines

  1. /*
  2.  * Preview_JavaDoc_Of_Current_Buffer.bsh
  3.  * version 1.8
  4.  * A BeanShell macro script for the jEdit text editor
  5.  *
  6.  *  $Header: /cvsroot/jedit/jEdit/macros/Java/Preview_JavaDoc_Of_Current_Buffer.bsh,v 1.1 2003/12/22 04:14:54 spestov Exp $
  7.  *  Copyright (C) 2001-2003 Tom Gutwin
  8.  *  tgutwin@webarts.bc.ca
  9.  *
  10.  *   - Macro to create and preview the JavaDocs for the current buffer
  11.  *   - It tries to figure everything out for you.
  12.  *   - Map this macro to it to a button on the button bar and away you go!
  13.  *
  14.  * ************************************************************************
  15.  * ** Requires the Console plugin and the InfoViewer plugin
  16.  * ** ALSO
  17.  * ** Requires Downloading of the different doclets if you are going to use
  18.  *    them and pdfReaderCommand if using the pdfDoclet.
  19.  * ***********************************************************************
  20.  * **  Features
  21.  * ***********************************************************************
  22.  *
  23.  *   - most of the settings to customize how this macro performs are set with
  24.  *     boolean flags (see code below).  The following features are some of the
  25.  *     features already selectable/customizable
  26.  *
  27.  *   - javadoc of current buffer OR current buffer's package
  28.  *       set the 'doFullPackage'  boolean flag in the macro code
  29.  *       You can then save a copy of this macro as a different name
  30.  *       for example...  Preview_JavaDoc_Of_Current_Buffers_Package.bsh
  31.  *
  32.  *   - default Doclet is the standard Java Doclet
  33.  *     (the user can change the default doclet to use by changing the XXXX
  34.  *      variable in this macro)
  35.  *
  36.  *   - When this macro starts, a doclet choice dialog is presented.
  37.  *     this dialog can be bypassed by setting 'showDocletDialog' to false
  38.  *     see the code below
  39.  *
  40.  *   - Many of the standard Doclet commandline parms are preset with some
  41.  *     defaults...     header, footer etc.
  42.  *     They are all controlled via boolean flags in the code
  43.  *     Switch them on/off as you like.
  44.  *
  45.  *   - Includes the ability to use 'user selectable' doclets
  46.  *     The following are already built in. (you just have to go get the doclet)
  47.  *      > the DocBook doclet - dbdoclet  http://www.michael-a-fuchs.de
  48.  *      > the Bouvard Doclet - http://web.tiscali.it/no-redirect-tiscali/farello/bp/intro.html
  49.  *      > the XMLDoclet - http://
  50.  *      > the pdfdoclet (Java API to PDF) - http://sourceforge.net/projects/pdfdoclet
  51.  *      > others
  52.  *
  53.  *   - easy selection of output dir (defaults to system temp dir)
  54.  *     set with the 'outputDir' var in the macro code
  55.  *
  56.  *   - other standard doclets parameters have been supervised by variables.
  57.  *     see below for adding extra classpath, source path, title, header, footer
  58.  *     MORE below
  59.  *
  60.  * ************************************************************************
  61.  * This program is free software; you can redistribute it and/or
  62.  * modify it under the terms of the GNU General Public License
  63.  * as published by the Free Software Foundation; either version 2
  64.  * of the License, or any later version.
  65.  *
  66.  * This program is distributed in the hope that it will be useful,
  67.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  68.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  69.  * GNU General Public License for more details.
  70.  *
  71.  * You should have received a copy of the GNU General Public License
  72.  * along with the jEdit program; if not, write to the Free Software
  73.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  74. USA.
  75.  */
  76.  
  77.  
  78. String _getClassName()
  79. {
  80.   /*
  81.    * Get_Class_Name.bsh - a BeanShell macro script for the
  82.    * jEdit text editor -  gets class name from buffer name
  83.    * Copyright (C) 2001 John Gellene
  84.    * jgellene@nyc.rr.com
  85.    *
  86.    * This program is free software; you can redistribute it and/or
  87.    * modify it under the terms of the GNU General Public License
  88.    * as published by the Free Software Foundation; either version 2
  89.    * of the License, or any later version.
  90.    *
  91.    * This program is distributed in the hope that it will be useful,
  92.    * but WITHOUT ANY WARRANTY; without even the implied warranty of
  93.    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  94.    * GNU General Public License for more details.
  95.    *
  96.    * You should have received a copy of the GNU General Public License
  97.    * along with the jEdit program; if not, write to the Free Software
  98.    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  99.    *
  100.    * $Id: Preview_JavaDoc_Of_Current_Buffer.bsh,v 1.1 2003/12/22 04:14:54 spestov Exp $
  101.    */
  102.   name = buffer.getName();
  103.   index = name.lastIndexOf('.');
  104.   return (index != -1 ? name.substring(0, index) : name);
  105. }
  106.  
  107. /** Trys to obtain the package name from the file **/
  108. String _determinePackageName()
  109. {
  110.   packageName = "";
  111.   text = buffer.getText(0, buffer.getLength());
  112.   //String lineSep = System.getProperty("line.separator");
  113.   /* look for the word package.
  114.     It must be at the start of a line.
  115.     It should not be within comments. (how can we easily determine this???)
  116.   */
  117.   packageWord = text.indexOf("package");
  118.   // If it is not on the first line of the file
  119.   // then look for the 1st occurence of "package" on its own line
  120.   if (packageWord > 0)
  121.     packageWord = text.indexOf("\npackage");
  122.  
  123.   if (packageWord != -1)
  124.   {
  125.     packageEOLine = text.indexOf(";", packageWord);
  126.     if (packageEOLine!= -1)
  127.       packageName = text.substring(packageWord+8,packageEOLine);
  128.   }
  129.   return packageName;
  130. }
  131.  
  132. /** Chooses a directory and returns the path. **/
  133. /* Use this method if you want to customize the macro to choose
  134.    output and input directorys for things */
  135. String _chooseADir(String dialogTitle, String startDir)
  136. {
  137.   String retVal = "";
  138.   JFileChooser chooser = new JFileChooser(startDir);
  139.   chooser.setDialogTitle(dialogTitle);
  140.   chooser.setMultiSelectionEnabled(false);
  141.   chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  142.   if(chooser.showDialog(view, "Okay") == JFileChooser.APPROVE_OPTION)
  143.   {
  144.     retVal = chooser.getSelectedFile().getAbsolutePath();
  145.   }
  146.   return retVal;
  147. }
  148.  
  149. void _infoView(View view, String urlStr)
  150. {
  151.   // first, check if the plugin is installed.
  152.   boolean version1 = false;
  153.   //With version 1.0 of the plugin ... the name changed to
  154.   //infoviewer.InfoViewerPlugin
  155.   if(jEdit.getPlugin("InfoViewerPlugin") == null)
  156.   {
  157.     if(jEdit.getPlugin("infoviewer.InfoViewerPlugin") == null)
  158.     {
  159.       Macros.error(view,"You must install the InfoViewerPlugin"
  160.               + " to use this macro.");
  161.       return;
  162.     }
  163.     version1 = true;
  164.   }
  165.   try
  166.   {
  167.     // API change with version 1.0 of the InfoViewer
  168.     if (version1)
  169.       jEdit.getPlugin("infoviewer.InfoViewerPlugin").
  170.         openURL(view, urlStr);// version 1.0
  171.     else
  172.       jEdit.getPlugin("InfoViewerPlugin").
  173.         sendURL(new URL(urlStr), view); // pre 1.0
  174.   }
  175.   catch (MalformedURLException mu)
  176.   {
  177.       Macros.error(view,"Cannot find the url " + urlStr);
  178.   }
  179. }
  180.  
  181. String _returnSystemCommand(View view, String command)
  182. {
  183.   // first, check if the plugin is installed.
  184.   if(jEdit.getPlugin("console.ConsolePlugin") == null)
  185.   {
  186.           Macros.error(view,"You must install the Console plugin"
  187.                   + " to use this macro.");
  188.           return;
  189.   }
  190.   //Macros.message(view, "Getting window manager.");
  191.   manager = view.getDockableWindowManager();
  192.   _console = (console.Console) manager.getDockable("console");
  193.   outputPane = _console.getOutputPane();
  194.  
  195.   text = outputPane.getText();
  196.   textLength = text.length();
  197.   runInSystemShell(view, command);
  198.   waitForConsole(view);
  199.   text = outputPane.getText();
  200.   textLength = text.length();
  201.   text = outputPane.getText().substring(textLength);
  202.   return text;
  203. }
  204.  
  205. /**
  206.  * Ensures that a folder exists.
  207.  * <TABLE WIDTH="100%" BORDER="0" CELLSPACING="1" CELLPADDING="2">
  208.  *  <TR><TD COLSPAN="2">
  209.  *   <H2>Ensures that a folder exists</H2>
  210.  *    </TD></TR>
  211.  *
  212.  *    <TR><TD COLSPAN="2"> <BR>
  213.  *    <B>Description:</B><BR>
  214.  *    use it like this:
  215.  *  <br>    _ensureFolderExists(new File(fileName).getParentFile());
  216.  *    </TD></TR>
  217.  *    </TABLE>
  218.  *
  219.  * @param folder  The File object to check.
  220.  **/
  221. void _ensureFolderExists(File folder)
  222. {
  223.   if ( folder != null  &&  ! folder.exists() )
  224.   {
  225.       _ensureFolderExists(folder.getParentFile());
  226.       folder.mkdir();
  227.   }
  228. }
  229.  
  230. String versionStr = "1.8";
  231. String SYSTEM_FILE_SEPERATOR = File.separator;
  232. String SYSTEM_TEMP_DIR = System.getProperty("java.io.tmpdir");
  233. //SYSTEM_TEMP_DIR = "/tmp";
  234. String SYSTEM_PATH_SEPERATOR = System.getProperty("path.separator");
  235.  
  236. // first, check if the plugin is installed.
  237. if(jEdit.getPlugin("console.ConsolePlugin") == null ||
  238.    (jEdit.getPlugin("InfoViewerPlugin") == null) &&
  239.    (jEdit.getPlugin("infoviewer.InfoViewerPlugin") == null))
  240. {
  241.   if(jEdit.getPlugin("console.ConsolePlugin") == null)
  242.     Macros.error(view,"You must install the Console plugin"
  243.             + " to use this macro.");
  244.   else
  245.     Macros.error(view,"You must install the InfoViewerPlugin plugin"
  246.             + " to use this macro.");
  247. }
  248. else
  249. {
  250.  
  251.   String currBufferPath = buffer.getPath();
  252.  
  253.   //Macros.message(view,"Current Buffer Path:\n"+currBufferPath);
  254.   if (currBufferPath.endsWith(".java"))
  255.   {
  256.     /* Store Some class/package/path info for use later */
  257.     // Get the Package name
  258.     String packName = _determinePackageName();
  259.  
  260.     // Get the Class Name
  261.     String className = _getClassName();
  262.  
  263.     /* ********************************************************************** */
  264.     /* Change the Following Vars to personalize things */
  265.     /* You should also Change the Header and Botton javadoc text down below */
  266.     /* ********************************************************************** */
  267.     // header message
  268.     String yourProductUrlStr = "http://www.yourProductURL.goes.here";
  269.     String yourProductNameStr = "My Java Product Name";
  270.  
  271.     // header message
  272.     String yourBottomStr = "Released under a GNU Public License.";
  273.  
  274.     // PDFDoclet outputfilename
  275.     String pdfDocletOutputFilename = "PDFDoclet.Output.pdf";
  276.  
  277.     // PDFDoclet outputfilename
  278.     String pdfReaderCommand = "acro";
  279.  
  280.     // Output directory .... set this to somewhere permanent if you want
  281.     String outputDir = SYSTEM_TEMP_DIR;
  282.  
  283.     // Allow choice of the output dir at runtime
  284.     boolean chooseOutputDir = false;
  285.  
  286.     // This macro attempts to get the source search path right
  287.     // if its not getting it... this var gets added to the Javadoc search path
  288.     String extraSourceDir = "";
  289.  
  290.     // This macro doesn't do much with the javadoc classpath
  291.     // if its not getting it... this var gets added to the Javadoc classpath
  292.     String extraClassesDir = "";
  293.  
  294.     // flag to do the Javadoc on the package instead of just the file
  295.     // Set this to true then save this macro with a new name
  296.     // ie... Preview_Javadoc_Of_Current_Package.bsh
  297.     boolean doFullPackage = false;
  298.  
  299.     // set to false to default to the standard java doclet
  300.     boolean showDocletDialog = true;
  301.  
  302.     /* Set some default options for the javadoc command */
  303.     /* change these to suit how you like your output to show up */
  304.     /* better yet... make a little dialog for input at runtime */
  305.     int showOnlyLevel = 3; // protected is the default
  306.     String[] showOnlyStr = {"-public ","-protected ","-package ","-private"};
  307.  
  308.     /* some (not All) standard doclet options */
  309.     /* ************************************** */
  310.     // if you want one of the following options...
  311.     // set the corresponding flag to true
  312.     boolean[] optionFlags = {false,false,false,false,false,
  313.                              false,false,false,false};
  314.     String[] optionStrs = {"-use ","-version ","-author ","-nosince","-notree ",
  315.                            "-noindex ","-nohelp ","-nodeprecated ","-verbose"};
  316.  
  317.     // beware OS/2 users...
  318.     // ALL the following options break the IBM 1.3.0 JDK Javadoc tool
  319.     // don't ask me?
  320.     boolean addWindowTitle = true;
  321.     StringBuffer windowTitle = new StringBuffer("-windowtitle \"Javadoc for");
  322.     windowTitle.append((doFullPackage?"package ":"class "));
  323.     windowTitle.append(className);
  324.     windowTitle.append("\" ");
  325.  
  326.     /* DocTitle Text */
  327.     boolean addDocTitle = true;
  328.     StringBuffer docTitle = new StringBuffer("-doctitle \"");
  329.     docTitle.append("Your Document Title here Javadoc API");
  330.     docTitle.append("\" ");
  331.  
  332.     /* Header Text */
  333.     boolean addHeader = true;
  334.     StringBuffer header = new StringBuffer("-header \"");
  335.     header.append("<B><A href=\"");
  336.     header.append(yourProductUrlStr);
  337.     header.append("\">");
  338.     header.append(yourProductNameStr);
  339.     header.append("</A></B>");
  340.     header.append("<BR>Version xx.xx.xx");
  341.     // Format the current time.
  342.      java.text.SimpleDateFormat formatter
  343.          = new java.text.SimpleDateFormat ("yyyy.MMMMM.dd 'at' hh:mm:sszzz");
  344.      java.util.Date currentTime_1 = new java.util.Date();
  345.      String dateString = formatter.format(currentTime_1);
  346.     header.append("<BR><font size=-1>");
  347.     header.append(dateString);
  348.     header.append("</font>\" ");
  349.  
  350.     /* Footer Text */
  351.     boolean addFooter = true;
  352.     StringBuffer footer = new StringBuffer("-footer \"");
  353.     footer.append("Produced Using the <A href=\"http://www.jedit.org\">");
  354.     footer.append("jEdit</A><BR>Preview Javadoc Beanshell Macro.<BR>");
  355.     footer.append("Copyright © 2001-2003, ");
  356.     footer.append("<A href=\"http://www.webarts.bc.ca>\"");
  357.     footer.append("Tom B. Gutwin</A>");
  358.     footer.append("\" ");
  359.  
  360.     /* Bottom Text */
  361.     boolean addBottom = true;
  362.     StringBuffer bottom = new StringBuffer("-bottom \"");
  363.     bottom.append(yourBottomStr);
  364.     bottom.append("\" ");
  365.  
  366.     /*********************************************************************** */
  367.     /* All users setting now complete */
  368.     /*********************************************************************** */
  369.  
  370.  
  371.     // Store the directory where the buffer file lives
  372.     String savedBufferdir = currBufferPath.substring(0,
  373.       currBufferPath.length()-6-className.length());
  374.  
  375.     // build the full package.classname
  376.     StringBuffer fullClassName = new StringBuffer();
  377.     if (packName != null && !packName.equals(""))
  378.     {
  379.       fullClassName.append(packName);
  380.       fullClassName.append(".");
  381.     }
  382.     fullClassName.append(className);
  383.  
  384.     /* Javadoc needs the file to live in a directory structure */
  385.     /* named like its Package name */
  386.     // If needed... copy the file to the temp dir into its package dir */
  387.     String currBufferdir = savedBufferdir;
  388.     StringBuffer tmpBufferName = new StringBuffer(SYSTEM_TEMP_DIR);
  389.     if (packName != null && !packName.equals("") &&
  390.         savedBufferdir.indexOf(
  391.           packName.replace('.',File.separatorChar).trim()) == -1 )
  392.     {
  393.       // The buffer file is not in an appropriate named dir
  394.       // copy and work on it in temp
  395.       if (!SYSTEM_TEMP_DIR.endsWith(SYSTEM_FILE_SEPERATOR))
  396.         tmpBufferName.append(SYSTEM_FILE_SEPERATOR);
  397.       _ensureFolderExists(new File(tmpBufferName.toString() +
  398.         packName.replace('.', File.separatorChar).trim()));
  399.       tmpBufferName.append(fullClassName.toString().
  400.         replace('.', File.separatorChar).trim());
  401.       tmpBufferName.append(".java");
  402.       //Macros.message(view, "Saving "+tmpBufferName.toString());
  403.       buffer.save(view, tmpBufferName.toString(), false);
  404.  
  405.       // the rest of the macro uses the currBufferdir variable
  406.       currBufferPath = tmpBufferName.toString();
  407.       currBufferdir = currBufferPath.substring(0,
  408.         currBufferPath.length()-6-className.length());
  409.     }
  410.  
  411.     // some debug statements
  412.     //Macros.message(view,"Package Name ="+packName);
  413.     //Macros.message(view,"fullClassName ="+fullClassName);
  414.     //Macros.message(view,"Buffer Path ="+currBufferPath);
  415.     //Macros.message(view,"Buffer Dir ="+currBufferdir);
  416.  
  417.  
  418.     /* ************************************************* */
  419.     /* ***********  On with the Processing ************* */
  420.     Object[] options = { "Standard Java Doclet", "Bouvard Doclet",
  421.                          "DocBook Doclet", "XML Doclet", "PDF Doclet" };
  422.     String[] docletClassName = { "", "bp.doclet.Bouvard",
  423.                                  "com.mf.doclet.docbook.DocBookDoclet",
  424.                                  "codeinsight.xmldoclet.XMLDoclet",
  425.                                  "com.tarsec.javadoc.pdfdoclet.PDFDoclet"};
  426.     String[] docletClassPath = { "", "Bouvard.jar", "dbdoclet.jar",
  427.                                  "xmldoclet.jar",
  428.                                  "pdfdoclet.jar:itext.jar:/usr/lib/pkgs" };
  429.     String PDFDocletConfigPropertiesFile = "pdfdoclet.config.properties";
  430.     // Set the DEFAULT Doclet to the JavaDoclet
  431.     String proceed = options[0];
  432.  
  433.     /* Shows a Doclet Selection Dialog */
  434.     if (showDocletDialog)
  435.       proceed = JOptionPane.showInputDialog(view,
  436.                             "Choose the Doclet to use for previewing the"+
  437.                             "\n" + className + " JavaDocs."+
  438.                             "\n(Bypass this dialog... set "+
  439.                             "'showDocletDialog=false;' in the macro)",
  440.                             "JavaDoc Buffer Macro - version "+versionStr,
  441.                             JOptionPane.QUESTION_MESSAGE, null, options,
  442.                             options[0]);
  443.  
  444.     if (proceed != null)
  445.     {
  446.       // this is where you could use the  _chooseADir(String startDir) method
  447.       // to choose an output dir at runtime.
  448.       if (chooseOutputDir)
  449.         outputDir = _chooseADir("Please Choose an Output Directory.",outputDir);
  450.  
  451.       docletChoice = 0;
  452.       for (int choiceNum = 0; choiceNum < options.length;choiceNum++)
  453.       {
  454.         if (((String)proceed).equals((String)options[choiceNum]))
  455.         {
  456.           docletChoice = choiceNum;
  457.           choiceNum = options.length;
  458.         }
  459.       }
  460.  
  461.       // The currBufferSrcDir expects the current buffer to be in a subDirectory
  462.       // path the same as the package name
  463.       // THIS is definitely NOT always the case
  464.       String currBufferSrcDir = currBufferPath.substring(0,
  465.         currBufferPath.length()-fullClassName.toString().length()-5);
  466.  
  467.       if(outputDir != null && !outputDir.equals(""))
  468.       {
  469.         // you might need some of the follwing if you want to add some
  470.         // commandline parms
  471.         String jedit_userdir=System.getProperty("user.home") +
  472.           SYSTEM_FILE_SEPERATOR +".jedit";
  473.         String jedit_homedir=jEdit.getJEditHome();
  474.         String currClassPath=System.getProperty("java.class.path");
  475.         String java_home=System.getProperty("java.home");
  476.  
  477.         // Construct the command which will be executed
  478.         StringBuffer command = new StringBuffer(java_home);
  479.         if (java_home.toLowerCase().endsWith("jre"))
  480.           command.append(File.separator).append("..");
  481.         command.append(File.separator).append("bin");
  482.         command.append(File.separator).append("javadoc ");
  483.  
  484.         if (!((String)proceed).equals((String)options[0]))
  485.         {
  486.           // general parms for 'other' doclets
  487.           command.append("-doclet \"");
  488.           command.append(docletClassName[docletChoice]);
  489.           command.append("\" ");
  490.           command.append("-docletpath \"");
  491.           command.append(jedit_userdir);
  492.           command.append(SYSTEM_FILE_SEPERATOR);
  493.           command.append("jars");
  494.           command.append(SYSTEM_FILE_SEPERATOR);
  495.           command.append(docletClassPath[docletChoice]);
  496.           command.append("\" ");
  497.  
  498.           // Bouvard Doclet
  499.           // This assumes the Bouvard.jar already exists
  500.           // in the jeditUser/jars dir
  501.           if (((String)proceed).equals((String)options[1]))
  502.           {
  503.             /* Specify the output dir */
  504.             command.append("-d \"");
  505.             command.append(outputDir);
  506.             command.append("\" ");
  507.           }
  508.  
  509.           // the DocBookDoclet has an extra parm
  510.           if (((String)proceed).equals((String)options[2]))
  511.           {
  512.             command.append("-properties \"");
  513.             command.append(jedit_userdir);
  514.             command.append(SYSTEM_FILE_SEPERATOR);
  515.             command.append("macros");
  516.             command.append(SYSTEM_FILE_SEPERATOR);
  517.             command.append("Java");
  518.             command.append(SYSTEM_FILE_SEPERATOR);
  519.             command.append("dbdoclet-xml.properties\" ");
  520.           }
  521.  
  522.           // the XMLDoclet has an extra parm
  523.           if (((String)proceed).equals((String)options[3]))
  524.           {
  525.             /* Specify the output dir */
  526.             //command.append("-d \"");
  527.             //command.append(outputDir);
  528.             //command.append("\" ");
  529.           }
  530.  
  531.           // the PDFDoclet has an extra parm
  532.           if (((String)proceed).equals((String)options[4]))
  533.           {
  534.             command.append("-pdf \"");
  535.             command.append(outputDir);
  536.             command.append(SYSTEM_FILE_SEPERATOR);
  537.             command.append(pdfDocletOutputFilename);
  538.             command.append("\" ");
  539.             if (PDFDocletConfigPropertiesFile != null
  540.               &&!PDFDocletConfigPropertiesFile.equals(""))
  541.             {
  542.               command.append(" -workdir \"");
  543.               command.append(outputDir);
  544.               command.append("\" ");
  545.               command.append("-config \"");
  546.               command.append(jedit_userdir);
  547.               command.append(SYSTEM_FILE_SEPERATOR);
  548.               command.append("macros");
  549.               command.append(SYSTEM_FILE_SEPERATOR);
  550.               command.append("Java");
  551.               command.append(SYSTEM_FILE_SEPERATOR);
  552.               command.append(PDFDocletConfigPropertiesFile);
  553.               command.append("\"");
  554.             }
  555.           }
  556.         }
  557.         else
  558.         { // standard doclet parms
  559.           if (addWindowTitle)
  560.             command.append(windowTitle.toString());
  561.           if (addDocTitle)
  562.             command.append(docTitle.toString());
  563.           if (addHeader)
  564.             command.append(header.toString());
  565.           if (addFooter)
  566.             command.append(footer.toString());
  567.           if (addBottom)
  568.             command.append(bottom.toString());
  569.  
  570.           /* add the on/off options */
  571.           for (int opt = 0; opt <optionFlags.length; opt++)
  572.           {
  573.             if (optionFlags[opt])
  574.               command.append(optionStrs[opt]);
  575.           }
  576.  
  577.           /* Specify the output dir */
  578.           command.append("-d \"");
  579.           command.append(outputDir);
  580.           command.append("\" ");
  581.         }
  582.  
  583.         /* Set the Level of detail to show */
  584.           command.append(" ");
  585.         command.append(showOnlyStr[showOnlyLevel]);
  586.  
  587.         /* if not found add your source dir to the 'extraClassesdir' var */
  588.         command.append(" -classpath \"");
  589.         command.append(SYSTEM_TEMP_DIR);
  590.         command.append(SYSTEM_PATH_SEPERATOR);
  591.         command.append(System.getProperty("java.class.path"));
  592.         command.append(SYSTEM_PATH_SEPERATOR);
  593.         command.append(extraClassesDir);
  594.         command.append("\" ");
  595.  
  596.         /* **** Done with the options ***** */
  597.         /* Specify the package or file name */
  598.         if (doFullPackage && packName != null && !packName.equals(""))
  599.         {
  600.           /* Guess where the package source is located */
  601.           /* if not found... add your source dir to the 'extraSourcedir' var */
  602.           command.append("-sourcepath \"");
  603.           command.append(savedBufferdir);
  604.           command.append(SYSTEM_PATH_SEPERATOR);
  605.           command.append(currBufferSrcDir);
  606.           command.append(SYSTEM_PATH_SEPERATOR);
  607.           command.append(currBufferSrcDir);
  608.           command.append(SYSTEM_FILE_SEPERATOR);
  609.           command.append("..");
  610.           command.append(SYSTEM_PATH_SEPERATOR);
  611.           command.append(currBufferSrcDir);
  612.           command.append(SYSTEM_FILE_SEPERATOR);
  613.           command.append("..");
  614.           command.append(SYSTEM_FILE_SEPERATOR);
  615.           command.append("..");
  616.           command.append(SYSTEM_PATH_SEPERATOR);
  617.           command.append(currBufferSrcDir);
  618.           command.append(SYSTEM_FILE_SEPERATOR);
  619.           command.append("..");
  620.           command.append(SYSTEM_FILE_SEPERATOR);
  621.           command.append("..");
  622.           command.append(SYSTEM_FILE_SEPERATOR);
  623.           command.append("..");
  624.           command.append(SYSTEM_PATH_SEPERATOR);
  625.           command.append(currBufferSrcDir);
  626.           command.append(SYSTEM_FILE_SEPERATOR);
  627.           command.append("..");
  628.           command.append(SYSTEM_FILE_SEPERATOR);
  629.           command.append("..");
  630.           command.append(SYSTEM_FILE_SEPERATOR);
  631.           command.append("..");
  632.           command.append(SYSTEM_FILE_SEPERATOR);
  633.           command.append("..");
  634.           command.append(SYSTEM_PATH_SEPERATOR);
  635.           command.append(currBufferdir);
  636.           command.append(SYSTEM_PATH_SEPERATOR);
  637.           command.append(extraSourceDir);
  638.           command.append("\" ");
  639.  
  640.           command.append(packName);
  641.         }
  642.         else
  643.         {
  644.           // add the base sourcepath
  645.           command.append("-sourcepath \"");
  646.           command.append(savedBufferdir);
  647.           command.append(SYSTEM_PATH_SEPERATOR);
  648.           command.append(currBufferSrcDir);
  649.           command.append(SYSTEM_PATH_SEPERATOR);
  650.           command.append(currBufferdir);
  651.           command.append(SYSTEM_PATH_SEPERATOR);
  652.           command.append(extraSourceDir);
  653.           command.append("\" ");
  654.  
  655.           // now add the file to javadoc
  656.           command.append("\"");
  657.           command.append(currBufferPath);
  658.           command.append("\"");
  659.         }
  660.  
  661.         retVal = _returnSystemCommand(view, command.toString());
  662.         if (retVal.indexOf("error") == -1)
  663.         {
  664.           // Build the url for the Viewer
  665.           // If you don't want to use the InfoViewer plugin...
  666.           // easy, change the implementation in this macros _infoView method
  667.           StringBuffer urlStr = new StringBuffer();
  668.           urlStr.append("file:///");
  669.           urlStr.append(outputDir.replace('\\', '/').trim());
  670.           if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  671.             urlStr.append("/");
  672.           if (doFullPackage)
  673.           {
  674.             urlStr.append("index.html");
  675.           }
  676.           else
  677.           {
  678.             if (packName != null && !packName.equals(""))
  679.             {
  680.               urlStr.append(packName.replace('.', '/').trim());
  681.               urlStr.append("/");
  682.             }
  683.             //Macros.message(view, packName);
  684.             urlStr.append(className);
  685.             urlStr.append(".html");
  686.             //Macros.message(view, urlStr.toString());
  687.           }
  688.  
  689.           // now which viewer (standard or Pecuchet)
  690.           if (!showDocletDialog || ((String)proceed).equals((String)options[0]))
  691.             _infoView(view, urlStr.toString());
  692.  
  693.           else if (((String)proceed).equals((String)options[1]))
  694.           {
  695.             // Bouvard Browser
  696.             // This assumes the Pecuchet.jar already exists
  697.             // and xerces is in the classpath already
  698.             StringBuffer classPath = new StringBuffer("\"");
  699.             classPath.append(jedit_userdir);
  700.             classPath.append(SYSTEM_FILE_SEPERATOR);
  701.             classPath.append("jars");
  702.             classPath.append(SYSTEM_FILE_SEPERATOR);
  703.             classPath.append("Pecuchet.jar");
  704.             classPath.append(SYSTEM_PATH_SEPERATOR);
  705.             classPath.append(jedit_homedir);
  706.             classPath.append(SYSTEM_FILE_SEPERATOR);
  707.             classPath.append("jars");
  708.             classPath.append(SYSTEM_FILE_SEPERATOR);
  709.             classPath.append("Pecuchet.jar");
  710.             classPath.append(SYSTEM_PATH_SEPERATOR);
  711.             classPath.append(currClassPath);
  712.             classPath.append("\"");
  713.  
  714.             StringBuffer bViewerCommand = new StringBuffer("java -classpath ");
  715.             bViewerCommand.append(classPath);
  716.             bViewerCommand.append(" ");
  717.             bViewerCommand.append("-Dorg.xml.sax.driver=");
  718.             bViewerCommand.append("org.apache.xerces.parsers.SAXParser");
  719.             bViewerCommand.append(" ");
  720.             bViewerCommand.append("bp.app.Main ");
  721.             bViewerCommand.append(outputDir);
  722.             if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  723.               bViewerCommand.append(SYSTEM_FILE_SEPERATOR);
  724.             bViewerCommand.append("data.bou &");
  725.             retVal = _returnSystemCommand(view, bViewerCommand.toString());
  726.             StringBuffer macroMessage =
  727.               new StringBuffer("When the Pecuchet browser starts.\n");
  728.             macroMessage.append("Open file: ");
  729.             macroMessage.append(outputDir);
  730.             if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  731.               macroMessage.append(SYSTEM_FILE_SEPERATOR);
  732.             macroMessage.append("data.bou");
  733.             //Macros.message(view, macroMessage.toString());
  734.           }
  735.           else if (((String)proceed).equals((String)options[2]))
  736.           {
  737.             // XML Doclet
  738.             // Use a new jEdit Buffer
  739.             StringBuffer newFile = new StringBuffer(outputDir);
  740.             if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  741.               newFile.append(SYSTEM_FILE_SEPERATOR);
  742.             newFile.append("Reference.xml");
  743.             Buffer newTmpBuffer = jEdit.openFile(view,newFile.toString());
  744.           }
  745.           else if (((String)proceed).equals((String)options[3]))
  746.           {
  747.             // XML Doclet
  748.             // Use a new jEdit Buffer
  749.             StringBuffer newFile = new StringBuffer(outputDir);
  750.             if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  751.               newFile.append(SYSTEM_FILE_SEPERATOR);
  752.             newFile.append("output.xml");
  753.             Buffer newTmpBuffer = jEdit.openFile(view,newFile.toString());
  754.           }
  755.           else if (((String)proceed).equals((String)options[4]))
  756.           {
  757.             // pdf Doclet
  758.             StringBuffer pdfViewerCommand = new StringBuffer(pdfReaderCommand);
  759.             pdfViewerCommand.append(" ");
  760.             pdfViewerCommand.append(outputDir);
  761.             pdfViewerCommand.append(SYSTEM_FILE_SEPERATOR);
  762.             pdfViewerCommand.append(pdfDocletOutputFilename);
  763.             retVal = _returnSystemCommand(view, pdfViewerCommand.toString());
  764.           }
  765.           else
  766.           {
  767.             // put the viewers for other doclets here
  768.           }
  769.         }
  770.         else
  771.           Macros.error(view, "Javadoc did NOT complete successfully. " +
  772.             "See the console output");
  773.       }
  774.     }
  775.   }
  776.   else
  777.     Macros.error(view, "Current Buffer does NOT appear to be a Java File");
  778. }
  779.  
  780. /*
  781.  
  782. Macro index data (in DocBook format)
  783.  
  784.   <listitem>
  785.     <para><filename>Preview_Javadoc_of_Buffer.bsh</filename></para>
  786.     <abstract><para>
  787.       Create and display API documentation for the current buffer.
  788.     </para></abstract>
  789.   <para>
  790.     The macro includes various configuration variables you can change; see the comment at the beginning of the macro source for details.
  791.   </para>
  792.   </listitem>
  793.  
  794. */
  795.  
  796. // end Preview_JavaDoc_of_Buffer.bsh
  797.  
  798.